import { useDetail, useList } from "@/hooks";
import { getUserInfoUrl } from "@/command/apiTool";
import { getAction } from "@/command/netTool";
import * as vant from "vant";
const { showFailToast, showSuccessToast } = vant;
export const useRequest = () => {
  // const list = Array(5).fill({});
  // const [data2] = useDetail("/", { list: list });
  // const [data4] = useDetail("/", { list: list });
  // 我的保供任务
  const [listOpen, listOpenControl] = useDetail(
    getUserInfoUrl({
      dh: "/api/H5/richHelpGuaranteedSupplyTask/large/listOpen",
      xh: "/api/H5/richHelpGuaranteedSupplyTask/small/listResult",
    }),
    []
  );
  // 最新快讯
  const [listTaskPartake] = useDetail(
    getUserInfoUrl({
      dh: "/api/H5/richHelpGuaranteedSupplyTask/large/listTaskPartake",
      xh: "/api/H5/richHelpGuaranteedSupplyTask/small/listTaskPartake",
    }),
    []
  );
  // 保供任务
  // 保供记录
  const [listAllYes] = useDetail(
    getUserInfoUrl({
      dh: "/api/H5/richHelpGuaranteedSupplyTask/large/listAllYes",
      xh: "/api/H5/richHelpGuaranteedSupplyTask/small/listAllYes",
    }),
    []
  );

  const btnAction = (url: any, params: any) => {
    getAction(url, { ...params }, { isResolve: true }).then((e) => {
      console.log("eee", e);
      showSuccessToast(e.msg);
      // 刷新接口
      listOpenControl.refresh();
    });
  };

  const accept = (id: any, status: any, userIds?: any) => {
    let Url = {
      dh: "/api/H5/richHelpGuaranteedSupplyTask/large/accept",
      xh: "/api/H5/richHelpGuaranteedSupplyTask/small/acceptOrRefuse",
    };
    const action = getUserInfoUrl(Url, {
      taskId: id,
      status: status,
      userIds: userIds,
    });
    btnAction(action.url, action.params);
  };

  const refuse = (id: any, status: any) => {
    let Url = {
      dh: "/api/H5/richHelpGuaranteedSupplyTask/large/accept",
      xh: "/api/H5/richHelpGuaranteedSupplyTask/small/acceptOrRefuse",
    };
    const action = getUserInfoUrl(Url, { taskId: id, status: status });
    btnAction(action.url, action.params);
  };

  // 结队小户列表
  const [memberList] = useDetail(
    getUserInfoUrl({
      dh: "/api/H5/richCourse/large/getMemberList",
      xh: "",
    }),
    []
  );
  return {
    listOpen,
    listAllYes,
    listTaskPartake,
    accept,
    refuse,
    memberList,
  };
};
